#include "SingleAddressTestSuite.h"

// TestCases -----

void SingleAddressTest::constructionTest()
{	
//	BOOST_CHECK_THROW( new SingleAddress( "localpart", "domain", "display" ) );
	t_address = boost::shared_ptr<SingleAddress>( new SingleAddress( "localpart", "domain", "display" ) );
}

void SingleAddressTest::accessMethodsTest()
{	
	BOOST_CHECK_EQUAL( t_address->displayName(), "display" );
	t_address->clearDisplayName();
	BOOST_CHECK_EQUAL( t_address->hasDisplayName(), false );
	BOOST_CHECK_EQUAL( t_address->localpart(), "localpart" );
	BOOST_CHECK_EQUAL( t_address->domain(), "domain" );
}

void SingleAddressTest::compareTest()
{
	compareLocalpart();
	compareDomain();
	compare()
}

// Pomocnicze

void SingleAddressTest::compareLocalpart()	{

	BOOST_CHECK_EQUAL( t_address->compareLocalpart( "localpart" ), SingleAddress::EQUAL );
	BOOST_CHECK_EQUAL( t_address->compareLocalpart( "localhost.localpart.localport" ), SingleAddress::NOT );
	BOOST_CHECK_EQUAL( t_address->compareLocalpart( "local" ), SingleAddress::NOT );
}

void SingleAddressTest::compareDomain()	{

	BOOST_CHECK_EQUAL( t_address->compareDomain( "domain" ), SingleAddress::EQUAL );
	BOOST_CHECK_EQUAL( t_address->compareDomain( "private.domain.edu.pl" ), SingleAddress::IS_CONTAINED );
	BOOST_CHECK_EQUAL( t_address->compareDomain( "dom" ), SingleAddress::CONTAINS );
}

void SingleAddressTest::compare()	{

	SingleAddress equal( "localpart", "domain" );
	SingleAddress another_display( "localpart", "domain", "another display name" );
	SingleAddress another( "domain", "localpart" );
	BOOST_CHECK_EQUAL( t_address->compare( equal ), SingleAddress::EQUAL );
	BOOST_CHECK_EQUAL( t_address->compare( another_display ), SingleAddress::NOT );
	BOOST_CHECK_EQUAL( t_address->compare( another ), SingleAddress::NOT );
}		

// TestSuite ----------------

SingleAddressTestSuite::SingleAddressTestSuite()
: test_suite( "test_suite_SingleAddress" )
{
	test = boost::shared_ptr<SingleAddressTest >( new SingleAddressTest() );
	test_case *construction = BOOST_CLASS_TEST_CASE(
		&SingleAddressTest::constructionTest, test );
	test_case *access = BOOST_CLASS_TEST_CASE(
		&SingleAddressTest::accessMethodsTest, test );
	test_case *compare = BOOST_CLASS_TEST_CASE(
		&SingleAddressTest::compareTest, test );

	add( construction );
	add( access );
	add( compare );
}
